{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "from BUC_min_sup import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义数据集\n",
    "transactions = [\n",
    "    {'A', 'B', 'C', 'D'},\n",
    "    {'A', 'B', 'D'},\n",
    "    {'A', 'C', 'D'},\n",
    "    {'B', 'C', 'D'},\n",
    "    {'A', 'B', 'C'},\n",
    "    {'B', 'C', 'E'},\n",
    "    {'A', 'B', 'C', 'E'},\n",
    "    {'A', 'D', 'E'},\n",
    "    {'B', 'C', 'D', 'E'},\n",
    "    {'A', 'B', 'C', 'D', 'E'},\n",
    "    {'A', 'B'},\n",
    "    {'C', 'D'},\n",
    "    {'B', 'C', 'D', 'E'},\n",
    "    {'A', 'C', 'D'},\n",
    "    {'B', 'D', 'E'}\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 设置最小支持度\n",
    "min_support = 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 运行 BUC 算法\n",
    "frequent_item_sets = buc_algorithm(transactions, min_support)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Item_set: {'C'}, Support: 11\n",
      "Item_set: {'D'}, Support: 11\n",
      "Item_set: {'E'}, Support: 7\n",
      "Item_set: {'A'}, Support: 9\n",
      "Item_set: {'B'}, Support: 11\n",
      "Item_set: {'C', 'D'}, Support: 8\n",
      "Item_set: {'E', 'D'}, Support: 5\n",
      "Item_set: {'B', 'A'}, Support: 6\n",
      "Item_set: {'C', 'B'}, Support: 8\n",
      "Item_set: {'E', 'C'}, Support: 5\n",
      "Item_set: {'E', 'B'}, Support: 6\n",
      "Item_set: {'C', 'A'}, Support: 6\n",
      "Item_set: {'D', 'B'}, Support: 7\n",
      "Item_set: {'D', 'A'}, Support: 6\n",
      "Item_set: {'E', 'A'}, Support: 3\n",
      "Item_set: {'C', 'D', 'B'}, Support: 5\n",
      "Item_set: {'E', 'C', 'D'}, Support: 3\n",
      "Item_set: {'E', 'D', 'B'}, Support: 4\n",
      "Item_set: {'C', 'D', 'A'}, Support: 4\n",
      "Item_set: {'E', 'C', 'B'}, Support: 5\n",
      "Item_set: {'C', 'B', 'A'}, Support: 4\n",
      "Item_set: {'D', 'B', 'A'}, Support: 3\n",
      "Item_set: {'E', 'C', 'D', 'B'}, Support: 3\n"
     ]
    }
   ],
   "source": [
    "# 输出频繁项集及其支持度\n",
    "for item_set, support in frequent_item_sets.items():\n",
    "    print(f\"Item_set: {set(item_set)}, Support: {support}\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorch",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
